package com.tanhua.server.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.server.mapper.QuestionMapper;
import com.tanhua.server.pojo.Question;
import com.tanhua.server.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class QuestionServiceImpl implements QuestionService {
    @Autowired
    private QuestionMapper questionMapper;


    public Question queryQuestion(Long userId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id", userId);
        return questionMapper.selectOne(queryWrapper);
    }

    @Override
    public void save(Long userId, String content) {
        Question question = queryQuestion(userId);
        if (null != question) {
            question.setTxt(content);
            this.questionMapper.updateById(question);
        } else {
            question = new Question();
            question.setUserId(userId);
            question.setTxt(content);
            this.questionMapper.insert(question);
        }
    }
}
